------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_869
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/analysis/fig_semitransitory.log
  log type:  text
 opened on:  27 Nov 2024, 17:58:37

. *
. * Plots UR*age and UR0*age coefficients from models run by runatc.do.
. *
. * Based on fig_URfx.do, 5/18/18
. * Edits:
. * 5/22/18, RY: Added new topcoded annual earnings variable (to be used for main analysis)  
. * 8/16/18, JR: Adjusted to accommodate normalization of effects for 10+ experience.
. * 9/29/18, NR: Sort by model depvar cvname fvval instead of by model depvar fvval
. * 1/21/19, NR: Adjusted yaxis (-0.8 to +0.2) and removed "yr" from xaxis labels
. * 9/17/19, NG: Added and updated figures 
. * 02/19/2020: NG:  Updated to keep only new figures used in the paper. 
. *                                  See  GRscarring/archive/archive_20200216_161201/programs/analysis/old for a older and longer ve
> rsion of this program 
. * 4/1/20, JR:  Rewritten completely
. 
. clear

. 
. cap project, doinfo

. //cap notaproject
. if _rc==0 {
.         local pdir "`r(pdir)'"                                                      // the project's main dir.
.         local dofile "`r(dofile)'"                                                  // do-file's stub name
.         local sig {bind:{hi:[`dofile'.dta. RP : `dofile'.do, `c(current_date)']}}   // a signature in notes
.         local doasproject=1
. }

. else {
.         local pdir "~/GRscarring"
.         local dofile "fig_semitransitory"
.         local doasproject=0
. }

. 
. set more off

. local rootdir "`pdir'"

. local thisdir "`pdir'"

. 
. local scratch "`pdir'/scratch"

. local rawdata "`pdir'/rawdata"

. local output "`pdir'/results"

. 
. if `doasproject'==1 {
.         project, uses(`scratch'/extrapolate_coeffs.dta)
project GRscar_erratum > do-file uses: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/extrapolate_coeffs.dta" filesig(3506803
> 25:2415967)
. }

. 
. local depvars "empl rw_l log_pearnval_tc_r"

. local wages "rw_l log_pearnval_tc_r"

. 
. set scheme s1color

. 
. use `scratch'/extrapolate_coeffs.dta, clear

. 
. keep if inlist(substr(model, 1, 2),"mC","mD","mE","mF") & ivartype=="Interaction"
(20,988 observations deleted)

. 
. ** As of 10/24/17, when the regressions are run the unemployment rate (independent variable)
. ** is in percentage points, while binary dependent variables such as unemployment are in
. ** percent.
. *Rescale for those outcomes where the dependent variable was measured in % but should be in p.p.
. // if depvar=="labfor" | depvar=="empl" | depvar=="unem" | depvar=="livewithprnt" | ///
. //    depvar=="married" | depvar=="lives_spouse_oth" | depvar=="chld_pr" {
. //      replace b=b*100 
. //      replace se=se*100
. // }
. 
. isid model depvar cvname fvval

. sort model depvar cvname fvval

. by model depvar cvname: assert fvval==8 if _n==_N

. expand 2 if fvval==8, gen(new)
(126 observations created)

. replace fvval=10 if new==1
(126 real changes made)

. drop new

. replace b=0 if fvval==10
(126 real changes made)

. replace se=0 if fvval==10
(126 real changes made)

. 
. 
. replace b=b*100 if inlist(depvar,"labfor", "empl", "unem", "livewithprnt", "married", "lives_spouse_oth", "chld_pr")
(200 real changes made)

. replace se=se*100 if inlist(depvar,"labfor", "empl", "unem", "livewithprnt", "married", "lives_spouse_oth", "chld_pr")
(200 real changes made)

. 
. label def scarringpath 0 "0-1 year" 2 "2-3 years" 4 "4-5 years" 6 "6-7 years" 8 "8-9 years" 10 "10+ years"

. label values fvval scarringpath

. 
. gen cil=b-2*se

. gen ciu=b+2*se

. 
. *individual dependent variable graphs - excess sensitivity
. 
. 
. rename fvval expcat

. gen agecat=expcat

. label define agecat_l 0 "22-23" 2 "24-25" 4 "26-27" 6 "28-29" 8 "30-31" 10 "32+"

. label values agecat agecat_l

. 
. gen expcatA=expcat-0.1

. gen expcatB=expcat+0.1

. gen agecatA=agecat-0.1

. gen agecatB=agecat+0.1

. 
. // One basic graph output
. cap program drop makescarplot

. program define makescarplot
  1.   syntax, depvar(string) e(real) plotver(real) effecttype(string) ///
>           xvar(string) modelseries(string) ///
>           [name(string) saving(string) gphtitle(string) shift yscal(string) legpos(string)]
  2.   
.   if "`xvar'"=="agecat" {
  3.     local xtitle "Age"
  4.     local xlabels=`"0 "22-23" 2 "24-25" 4 "26-27" 6 "28-29" 8 "30-31" 10 "32+""'
  5.   }
  6.   else if "`xvar'"=="expcat" {
  7.     local xtitle "Potential experience (years)"
  8.     local xlabels=`"0 "0-1" 2 "2-3" 4 "4-5" 6 "6-7" 8 "8-9" 10 "10+""'
  9.   }  
 10.   else {
 11.     di "Need to specify x variable"
 12.     error
 13.   }
 14.   if "`shift'"=="shift" {
 15.     local xvarA `xvar'A
 16.     local xvarB `xvar'B
 17.   }
 18.   else {
 19.     local xvarA `xvar'
 20.     local xvarB `xvar'
 21.   }
 22.   if `"`gphtitle'"'==`""' {
 23.     if "`depvar'"=="empl" {
 24.       local gphtitle "A. Employment"
 25.     }
 26.     if "`depvar'"=="rw_l" {
 27.       local gphtitle "B. Log wages"
 28.     }
 29.   }
 30.     if "`depvar'"=="empl" {
 31.       if "`yscal'"=="" local yscal "yscale(range(-1.1 0.4)) ylabel(-0.8 (0.4) 0.4)"
 32.     }
 33.     if "`depvar'"=="rw_l" {
 34.       if "`yscal'"=="" local yscal "yscale(range(-0.023 0.01)) ylabel(-0.02 (0.01) 0.01)"
 35.     }
 36.     
.   
.   if `plotver'==1 { // Base plots for main paper -- models C and D, with alternative series
 37.     if "`effecttype'" == "sensitivity" {
 38.       local ytitle "Effect of contemporaneous UR"
 39.       local altlegend "Controlling for scarring effects"
 40.       local basemodel "mC`e'`modelseries'"
 41.       local altcv "ur_st"
 42.     }
 43.     if "`effecttype'" == "scarring" {
 44.       local ytitle "Effect of entry UR"
 45.       local altlegend "Controlling for excess sensitivity effects"
 46.       local basemodel "mD`e'`modelseries'"
 47.       local altcv "ur0"
 48.     }
 49. 
.     if "`legpos'"=="none" local legtext "legend(off)"
 50.     else local legtext `"legend(order(2 4) label(2 "Base Model") label(4 "Model with scarring &" "sensitivity effects") rowgap(
> 1) cols(1) ring(0) pos(`legpos'))"'
 51.         if `"`saving'"'~=`""' local savtext `"saving(`saving', replace)"'
 52.         if `"`name'"'~=`""' local nametext `"name(`name', replace)"'
 53.   
.       twoway rcap cil ciu `xvarA' if model=="`basemodel'" & depvar=="`depvar'"|| ///
>              scatter b `xvarA' if model=="`basemodel'" & depvar=="`depvar'",  msymbol(X)  lstyle(p1) mstyle(p1) || ///
>              rcap cil ciu `xvarB' if model=="mE`e'`modelseries'" & depvar=="`depvar'" & cvname=="`altcv'", mstyle(p2) lstyle(p2) |
> | ///
>              scatter b `xvarB' if model=="mE`e'`modelseries'" & depvar=="`depvar'" & cvname=="`altcv'", msymbol(Th) mstyle(p2)  ||
> , ///
>                `legtext' ///
>                title("`gphtitle'", pos(12)) ///
>                xlabel(`xlabels') ///
>                yline(0, lcolor(gray)) `yscal' ///
>                xtitle(`xtitle') ytitle(`ytitle') ///
>                `savtext' `nametext'
 54.   }
 55.   if `plotver'==2 { // Scarring model that includes both state and national unemployment rates
 56.     if "`legpos'"=="none" local legtext "legend(off)"
 57.     else local legtext `"legend(order(2 "State UR" 4 "National UR") cols(1) ring(0) pos(`legpos'))"'
 58.     twoway rcap cil ciu `xvarA' if model=="mF1`modelseries'" & depvar=="`depvar'" & cvname=="ur0" || ///
>            scatter b `xvarA' if model=="mF1`modelseries'" & depvar=="`depvar'" & cvname=="ur0", ///
>                    msymbol(X) lstyle(p1) mstyle(p1) || ///
>            rcap cil ciu `xvarB' if model=="mF1`modelseries'" & depvar=="`depvar'" & cvname=="ur0_nat", ///
>                    mstyle(p2) lstyle(p2) || ///
>            scatter b `xvarB' if model=="mF1`modelseries'" & depvar=="`depvar'" & cvname=="ur0_nat", ///
>                    lstyle(p2) mstyle(p2) ||, ///
>            `legpos' ///
>                title("`gphtitle'", pos(12)) ///
>                xlabel(`xlabels') ///
>                yline(0) ylabel(`yscal') ///
>                xtitle(`xtitle') ytitle(`ytitle') ///
>                `savtext' `nametext'
 59.   }       
 60. end

. 
. 
.  // Models:
.      // A: No time:Just cohort, age, and state effects -- no time effects
.      // B: Basic: Age-time-cohort + state FEs
.      // C: Excess sensitivity: A-T-C + UR(t)*Agroups
.      // D: Scarring: A-T-C + UR(0)*Agroups
.      // E: Scarring. + excess sensitivity: A-T-C + UR(t)*Agroups + UR(0)*Agroups
.     // F : Same as D but with interactions between age and both the state and national unemployment rates
.      // b versions of each that include all cohorts
.      // Zb: Just contrast between 2005/6 and 2010/11 cohorts (measured by age when 22).
.      //a models: Main estimation sample, excluding recent cohorts
.      //b models: Full sample
.      //c models: Full sample, exclude <24.
.      //d models: Main estimation sample, use national UR
. 
. 
.  
. 
. 
. // Base graphs for paper
.   makescarplot, depvar(empl) e(1) plotver(1) effecttype(sensitivity) xvar(agecat) shift /// 
>                 modelseries(b) saving("`output'/`dofile'_sensitivity_empl.gph") legpos(none) ///
>                 name(sensitivity_empl) gphtitle("B. Employment - excess sensitivity")
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_sensitivity_empl.gph saved

.   makescarplot, depvar(empl) e(1) plotver(1) effecttype(scarring) xvar(agecat) shift /// 
>                 modelseries(b) saving("`output'/`dofile'_scarring_empl.gph") legpos(none) ///
>                 name(scarring_empl) gphtitle("A. Employment - scarring")
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_scarring_empl.gph saved

.   makescarplot, depvar(rw_l) e(1) plotver(1) effecttype(sensitivity) xvar(agecat) shift /// 
>                 modelseries(b) saving("`output'/`dofile'_sensitivity_rw_l.gph") legpos(none) ///
>                 name(sensitivity_rw_l) gphtitle("D. Log wages - excess sensitivity")
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_sensitivity_rw_l.gph saved

.   makescarplot, depvar(rw_l) e(1) plotver(1) effecttype(scarring) xvar(agecat) shift /// 
>                 modelseries(b) saving("`output'/`dofile'_scarring_rw_l.gph") legpos(4) ///
>                 name(scarring_rw_l) gphtitle("C. Log wages - scarring")
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_scarring_rw_l.gph saved

. 
. graph combine scarring_empl sensitivity_empl scarring_rw_l sensitivity_rw_l

. 
. graph combine scarring_empl sensitivity_empl, saving(`output'/`dofile'_empl.gph, replace)
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_empl.gph saved

. graph combine scarring_rw_l sensitivity_rw_l, saving(`output'/`dofile'_rw_l.gph, replace)
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_rw_l.gph saved

. 
. 
. // Using just those from earlier cohorts
.   makescarplot, depvar(empl) e(1) plotver(1) effecttype(sensitivity) xvar(agecat) shift /// 
>                 modelseries(a) legpos(4)  ///
>                 name(sensitivity_empl_older) gphtitle("B. Employment - excess sensitivity")

.   makescarplot, depvar(empl) e(1) plotver(1) effecttype(scarring) xvar(agecat) shift /// 
>                 modelseries(a) legpos(none) ///
>                 name(scarring_empl_older) gphtitle("A. Employment- scarring")

.   makescarplot, depvar(rw_l) e(1) plotver(1) effecttype(sensitivity) xvar(agecat) shift /// 
>                 modelseries(a) legpos(4)  ///
>                 name(sensitivity_rw_l_older) gphtitle("D. Log wages - excess sensitivity")

.   makescarplot, depvar(rw_l) e(1) plotver(1) effecttype(scarring) xvar(agecat) shift /// 
>                 modelseries(a) legpos(none) ///
>                 name(scarring_rw_l_older) gphtitle("C. Log wages - scarring")

. graph combine scarring_empl_older sensitivity_empl_older, saving(`output'/`dofile'_empl_older.gph, replace)
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_empl_older.gph saved

. graph combine scarring_rw_l_older sensitivity_rw_l_older, saving(`output'/`dofile'_rw_l_older.gph, replace)
file /accounts/projects/jr_ra/GRscarring/erratum/results/fig_semitransitory_rw_l_older.gph saved

. 
.  
. // Models that include both state and national URs
. //foreach d in empl rw_l {
. //  makescarplot, depvar(`d') e(1) plotver(2) effecttype(scarring) xvar(agecat) shift /// 
. //                modelseries(b) saving("`output'/extras/`dofile'_scarring_`d'_natlUR.gph")
. //}
.   save `scratch'/`dofile', replace
(file /accounts/projects/jr_ra/GRscarring/erratum/scratch/fig_semitransitory.dta not found)
file /accounts/projects/jr_ra/GRscarring/erratum/scratch/fig_semitransitory.dta saved

. 
. if `doasproject'==1 {
.   project, creates(`scratch'/`dofile'.dta)
project GRscar_erratum > do-file creates: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/fig_semitransitory.dta" filesig(4107
> 975143:147600)
. }

. 
. foreach d in empl rw_l {
  2.   if `doasproject'==1 {
  3.     project, creates(`output'/`dofile'_sensitivity_`d'.gph)
  4.     project, creates(`output'/`dofile'_scarring_`d'.gph)
  5.     project, creates(`output'/`dofile'_`d'.gph)
  6.     project, creates(`output'/`dofile'_`d'_older.gph)
  7.   }
  8. }
project GRscar_erratum > do-file creates: "results/fig_semitransitory_sensitivity_empl.gph" filesig(1951348614:11781)
project GRscar_erratum > do-file creates: "results/fig_semitransitory_scarring_empl.gph" filesig(2638962501:11765)
project GRscar_erratum > do-file creates: "results/fig_semitransitory_empl.gph" filesig(3571078373:24478)
project GRscar_erratum > do-file creates: "results/fig_semitransitory_empl_older.gph" filesig(3336421009:24647)
project GRscar_erratum > do-file creates: "results/fig_semitransitory_sensitivity_rw_l.gph" filesig(2728942393:11843)
project GRscar_erratum > do-file creates: "results/fig_semitransitory_scarring_rw_l.gph" filesig(710179849:12185)
project GRscar_erratum > do-file creates: "results/fig_semitransitory_rw_l.gph" filesig(1430759939:24833)
project GRscar_erratum > do-file creates: "results/fig_semitransitory_rw_l_older.gph" filesig(1050613355:24691)

. 
. */
. 
end of do-file
      name:  plog_869
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/analysis/fig_semitransitory.log
  log type:  text
 closed on:  27 Nov 2024, 17:58:53
------------------------------------------------------------------------------------------------------------------------------------
